package com.qf.news.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.news.entity.NewsDetail;
import com.qf.news.mapper.NewsDetailMapper;
import com.qf.news.service.NewsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/8 8:25
 * @Version 1.0
 */
@Service
public class NewsDetailServiceImpl implements NewsDetailService {
    @Autowired
    private NewsDetailMapper newsDetailMapper;
    @Override
    public PageInfo<NewsDetail> findAll(Integer page,Integer rows) {
        //1.分页
        PageHelper.startPage(page,rows);
        //2.查询
        List<NewsDetail> newsDetailList = newsDetailMapper.selectByExample(null);
        //3.分装PageInfo
        PageInfo<NewsDetail> pageInfo = new PageInfo<>(newsDetailList);
        //4.返回
        return pageInfo;
    }

    @Override
    public void delete(Integer id) {
        int i = newsDetailMapper.deleteByPrimaryKey(id);
        if(i==0){
            System.out.println("删除新闻失败");
            throw new RuntimeException("删除新闻失败");
        }
        System.out.println("删除新闻成功");
    }
}
